package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.aop.anno.LogAnno;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: hm
 * @Date: 2025/10/06 22:19
 * @Description:
 */
@Slf4j
@RestController
@SuppressWarnings("all")
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping("/subject/{subject}")
    public Result getBySubject(@PathVariable Integer subject){
        List<Course> subjectResult = courseService.getBySubject(subject);
        return Result.success(subjectResult);
    }


    @GetMapping("/list")
    public Result queryAllCourses(){
        List<Course> queryResult = courseService.queryAllCourses();
        return Result.success(queryResult);
    }

    @LogAnno
    @PutMapping
    public Result update(@RequestBody Course course) {
        courseService.update(course);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Course course = courseService.getById(id);
        return Result.success(course);
    }

    @LogAnno
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Integer id) {
        courseService.deleteById(id);
        return Result.success();
    }

    @GetMapping
    public Result page(CourseDTO dto) {
        PageResult<Course> pageResult = courseService.page(dto);
        return Result.success(pageResult);
    }


    @LogAnno
    @PostMapping
    public Result addCourse(@RequestBody Course course) {
        courseService.addCourse(course);
        return Result.success();
    }
}
